package com.tjp.subject.domain.handler.subject;

import com.tjp.subject.common.enums.SubjectInfoTypeEnum;
import com.tjp.subject.domain.convert.SubjectBriefConverter;
import com.tjp.subject.domain.entity.SubjectInfoBO;
import com.tjp.subject.domain.entity.SubjectOptionBO;
import com.tjp.subject.infra.basic.entity.SubjectBrief;
import com.tjp.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * @program: jz-club
 * @description: 简答题抽象接口策略类
 * @author: aaronTang
 * @create: 2024-02-29
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler {

    @Resource
    private SubjectBriefService subjectBriefService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        //实际往表中插入简答题的逻辑
        List<SubjectBrief> subjectBriefList = new LinkedList<>();
        subjectInfoBO.getOptionList().forEach(option -> {
            SubjectBrief subjectBrief = SubjectBriefConverter.INSTANCE.convertBOToBriefEntity(option);
            //设置对应的题目id
            subjectBrief.setSubjectId(subjectInfoBO.getId());
            subjectBriefList.add(subjectBrief);
        });

        subjectBriefService.batchInsert(subjectBriefList);

    }

    @Override
    public SubjectOptionBO query(Long subjectId) {
        return null;
    }
}
